package com.cloud.jucTest;

/**
 * 验证volatile不能保证原子性
 */
public class VolatileTest extends Thread{
    private static volatile Integer res = 0;

    @Override
    public void run () {
        for (int i = 0; i < 100; ++i) {
            res++;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10 ; ++i) {
            new VolatileTest().start();
        }
        Thread.sleep(2000);
        System.out.println("the fially resutl is " + res);
    }
}
